<template>
	<view>
		<!-- //搜索 -->
		<Search></Search>
		<!-- // 轮播 -->
		<Swiperi :bannerdata="bannerdata"></Swiperi>
		<!-- 抢购 -->
		<Purchase :recomdata="recomdata"></Purchase>
		<!--// 榜单 -->
		<List :billdata="billdata"></List>
		<!-- 卡片 -->
		<Card :carddata="carddata"></Card>
		<!-- 上拉加载 -->
		<TheDropdown ref="refresh"></TheDropdown>
	</view>
</template>

<script>
// 搜索
import Search from '../commentens/indexList/search/search.vue';
// 轮播
import Swiperi from '../commentens/indexList/swiper/swiper.vue';
// 抢购
import Purchase from '../commentens/indexList/purchase/purchase.vue';
// 榜单
import List from '../commentens/indexList/list/list.vue';
// 卡片
import Card from '../commentens/indexList/card/card.vue';
// <!-- 上拉加载 -->
import TheDropdown from '../commentens/indexList/theDropdownIoad/theDropdownIoad.vue';
export default {
	components: {
		Search,
		Swiperi,
		Purchase,
		List,
		Card,
		TheDropdown
	},
	data() {
		return {
			bannerdata: [],
			recomdata: [],
			billdata: [],
			carddata: [],
			//分页数
			pageid: 0
		};
	},
	onLoad() {},

	methods: {
		async indexRequest() {
			// 轮播
			let banner = new this.Request(this.Usls.m().bannreget).modeget();
			// 推荐抢购商品
			let recom = new this.Request(this.Usls.m().getrecommurl).modeget();
			// 天猫榜单
			let list = new this.Request(this.Usls.m().tmallList).modeget();
			// 卡片
			let card = new this.Request(this.Usls.m().commodcradurl + '?page=' + this.pageid).modeget();
			try {
				let res = await Promise.all([banner, recom, list, card]);
				console.log(res[3].data);
				// 轮播
				this.bannerdata = res[0].data;
				// 抢购商品
				this.recomdata = res[1].data;
				// 天猫榜单
				this.billdata = res[2].data;
				// 卡片
				this.carddata = res[3].data;
			} catch (e) {
				//TODO handle the exception
			}
		},
		// 下拉加载
		async theDropdownIoad() {
			try {
				let card = await new this.Request(this.Usls.m().commodcradurl + '?page=' + this.pageid).modeget();
				console.log('下拉加载');
				// 把之前得到的数据和上拉之后得到的数据做一个数组合并
				console.log(card.data);
				setTimeout(() => {
					if (card.data.length == 0) {
						// 方法
						this.$refs.refresh.loAd({ wether: true, title: '没有更多了', pictuer: true });
					} else {
						this.carddata = [...this.carddata, ...card.data];
					}
				}, 1000);

				console.log(this.carddata);
			} catch (e) {
				//TODO handle the exception
			}
		}
	},
	mounted() {
		this.indexRequest();
	},
	// 下拉加载
	onReachBottom() {
		this.$refs.refresh.loAd({ wether: true });
		console.log('到底了');
		console.log(this.$refs.refresh.loAd)
		this.pageid++;           //分页
		console.log(this.pageid);
		this.theDropdownIoad();
	}
};
</script>

<style>
page {
	background-color: #f4f4f4;
}
</style>
